package common.test;

import common.ListNode;

import java.util.ArrayList;
import java.util.List;

public class Palindrome {

    public boolean isPalindrome(ListNode head) {
        if (head == null) {
            return false;
        }
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        for (int i = 0, j = list.size() - 1; i < j; i++, j--) {
            if (list.get(i).compareTo(list.get(j)) != 0) {
                return false;
            }
        }
        return true;
    }
}
